# Maintainer:
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Thomas Weißschuh <thomas t-8ch.de>
# Contributor: George Brooke <george+arch.aur@george-brooke.co.uk>
# Contributor: Sebastian Wiesner <lunaryorn googlemail com>

_name=tox
pkgname=python-tox
pkgver=4.11.1
pkgrel=1
pkgdesc='Python virtualenv management and testing tool'
arch=('any')
url='https://tox.readthedocs.io'
license=('GPL2')
depends=(
  'python'
  'python-cachetools'
  'python-chardet'
  'python-colorama'
  'python-filelock'
  'python-packaging'
  'python-platformdirs'
  'python-pluggy'
  'python-pyproject-api'
  'python-virtualenv'
)
makedepends=(
  'python-build'
  'python-hatch-vcs'
  'python-hatchling'
  'python-installer'
  'python-wheel'
)
checkdepends=(
  # 'python-devpi-process'  # NOTE: pulls in devpi-{client,server}
  'python-diff-cover'
  'python-distlib'
  'python-flaky'
  'python-pytest'
  'python-pytest-mock'
  'python-psutil'
  'python-re-assert'
  # 'python-time-machine'  # NOTE: needed?
)
optdepends=(
  'python-pytest: for pytest plugin to test tox and its plugins'
  'python-pytest-mock: for pytest plugin to test tox and its plugins'
  'python-re-assert: for pytest plugin to test tox and its plugins'
)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha512sums=('8dc99f98a72ece1cae60e9a0d99fe44b66bd6d9fe6f2d45b0f4e7ab10a5e4a65049cced4b212fe8bfe34ded65b8e4b76d642e5c014d385d2d2cd7f87d8cf6816')
b2sums=('24926218c45f9d05e926ee2f0583a49e6ae11c6aa0344ea1b88c636ef67e945f5b54db565c1a5e242ca3e1bb7c065f92a7ce2ceb836b02e239b2321ad3d6c359')

prepare() {
  find $_name-$pkgver -name "*.pyc" -delete
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  # TODO: package remaining checkdepends
  # pytest "${pytest_options[@]}"
}

package() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  # add legacy symlink
  ln -sv tox "$pkgdir"/usr/bin/tox3
}
